package com.ghy.springbootrabbitmq.production;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定义队列和交换机
 */
@Configuration
public class QueueConfig {
    @Bean(name="confirmTestExchange")
    public FanoutExchange confirmTestExchange(){
        return new FanoutExchange("confirmTestExchange",true,false);
    }
    @Bean(name="directExchange")
    public DirectExchange directExchange(){
        return new DirectExchange("directExchange",true,false);
    }

    @Bean(name = "confirmTestQueue")
    public Queue confirmTestQueue(){
        return new Queue("confirm_test_queue",true,false,false);
    }

    @Bean
    public Binding confirmTestFanoutExcangeAndQueue(@Qualifier("confirmTestQueue")Queue queue,@Qualifier("confirmTestExchange") FanoutExchange fanoutExchange){
        return  BindingBuilder.bind(queue).to(fanoutExchange);
    }
    @Bean
    public Binding  directExchangeExcangeAndQueue(@Qualifier("confirmTestQueue")Queue queue,@Qualifier("directExchange") DirectExchange directExchange){
        return  BindingBuilder.bind ( queue ).to ( directExchange ).with("direct");
    }
}
